/**
 * @name 节点工厂
 * @des 包装、输出节点
 */
import { Injectable } from "@angular/core";
import { ProcessService } from "src/app/server/process.service";

@Injectable({
    providedIn: "root",
})
export class NodeFactoryService {
    actionNodeTpl = {};

    constructor(private pSrv: ProcessService) {}

    createPnode(type) {}
    /** 动作节点（单个） */
    createActionPnode(x = 0, y = 0, pid = null, mode = 0) {
        const id = this.pSrv.UUid();
        return {
            x,
            y,
            id,
            pid,
            type: 0,
            config: {
                mode,
                name: "测试测试",
            },
        };
    }
    /** 条件节点（多个，不能单独存在） */
    createConditionPnodes(x = 0, y = 0, pid = null, mode = 0) {
        const id1 = this.pSrv.UUid();
        const id2 = this.pSrv.UUid();
        const id3 = this.pSrv.UUid();
        return [
            {
                x,
                y,
                id: id1,
                pid,
                type: 1,
                config: {
                    mode,
                    isRoot: true,
                },
            },
            {
                x: x + 1,
                y,
                id: id2,
                pid: id1,
                type: 1,
                config: {
                    mode,
                    isRoot: false,
                    time: new Date(),
                },
            },
            {
                x: x + 1,
                y: y + 1,
                id: id3,
                pid: id2,
                type: 1,
                config: {
                    mode,
                    isRoot: false,
                    time: new Date(),
                },
            },
        ];
    }

    /** 创建条件节点 - 时间节点 */
    createTimePnodeInCondition(x = 0, y = 0, pid = null, mode = 0) {
        const id = this.pSrv.UUid();
        return {
            x,
            y,
            id,
            pid,
            type: 1,
            config: {
                mode,
                isRoot: false,
                time: new Date(),
            },
        };
    }
    /** 流程节点 */
    createProcessPnode(x = 0, y = 0, pid = null, mode = 0) {
        const id = this.pSrv.UUid();
        return {
            x,
            y,
            id,
            pid,
            type: 2,
            config: {
                mode,
            },
        };
    }
    /** 辅助节点 */
    createHelperPnode(x = 0, y = 0, pid = null, mode?) {
        const id = this.pSrv.UUid();
        return {
            x,
            y,
            id,
            pid,
            type: 3,
        };
    }
}
